package com.wordpress.minhnvt1;

import com.wordpress.minhnvt1.candidate.AddCandidate;
import com.wordpress.minhnvt1.candidate.ListCandidate;
import com.wordpress.minhnvt1.hr.MyProfile;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ManagementForm extends Activity {
	private String _hrId;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.managementform);
        
        Intent i = this.getIntent();
        _hrId = i.getStringExtra("hrId");
        
        ListView lv = (ListView)findViewById(R.id.lvMgtList);
        
        String[] list = getResources().getStringArray(R.array.management_array);
        
        lv.setAdapter(new ArrayAdapter<String>(this, R.layout.customlist, R.id.list_content, list));
        
        lv.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				if (position == 2) {
					toMyProfile();
				}
				
				if (position == 1) {
					toAddCandidate();
				}
				
				if (position == 0) {
					toListCandicates();
				}
			}
		});
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		
		inflater.inflate(R.menu.managementmenu, menu);
		return true;
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.menuMgtAddcandidate:
			toAddCandidate();
			return true;
		case R.id.menuMgtChangepass:
			toMyProfile();
			return true;
		case R.id.menuMgtLogout:
			Intent intent = new Intent(getApplicationContext(), MainActivity.class);
			startActivity(intent);
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}
	protected void toListCandicates() {
		Intent intent = new Intent(getApplicationContext(), ListCandidate.class);
		intent.putExtra("hrId", _hrId);
		startActivity(intent);
	}

	protected void toAddCandidate() {
		Intent intent = new Intent(getApplicationContext(), AddCandidate.class);
		intent.putExtra("hrId", _hrId);
		startActivity(intent);
	}

	protected void toMyProfile() {
		Intent intent = new Intent(getApplicationContext(), MyProfile.class);
		intent.putExtra("hrId", _hrId);
		startActivity(intent);	
	}
}
